﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using LogManager.Base;
using LogManager.Base.Data;

namespace LogManager.Config.Data
{
    public class ConfigServerService : IServerService
    {
        private readonly IQueryable<IServer> _servers;

        public ConfigServerService(ServerCollection serverCollection)
        {
            _servers = serverCollection.Cast<ServerConfiguration>()
                .AsQueryable();
        }

        #region IServerRepository Members

        public IQueryable<IServer> Query()
        {
            return _servers;
        }

        public IEnumerable<IServer> All()
        {
            return _servers;
        }

        public IServer Get(string serverName)
        {
            return _servers.Where(s => s.ServerName == serverName).SingleOrDefault();
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        #endregion
    }
}